package com.zonekey.config;


import com.zonekey.handle.AuthExceptionEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * @description:
 * @author: 靳俊英
 * @create: 2021-05-21 16:38
 **/
@Configuration
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    /**
     * 捕获，添加自定义异常处理
     */
    @Autowired
    private AuthExceptionEntryPoint authExceptionEntryPoint;

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.authenticationEntryPoint(authExceptionEntryPoint);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .headers().frameOptions().disable()
                .and()
                .authorizeRequests()
                .antMatchers("/auth/oauth/token",
                "/auth/logout","/auth/add/client",
                        "/auth/add/client/simple").permitAll()
                .anyRequest().authenticated()
                .and()
                .csrf().disable();
    }


}
